// 简单的按键测试（不检测PowerPoint）
const { exec } = require('child_process');
const { promisify } = require('util');

const execAsync = promisify(exec);

async function testSimpleKeys() {
  console.log('========================================');
  console.log('简单按键测试');
  console.log('========================================\n');

  console.log('请确保PowerPoint已打开并在前台，测试将在5秒后开始...');
  await sleep(5000);

  try {
    console.log('发送右箭头键...');
    const psScript1 = `
      Add-Type -AssemblyName System.Windows.Forms
      [System.Windows.Forms.SendKeys]::SendWait("{RIGHT}")
    `;

    await execAsync(`powershell -Command "${psScript1}"`, { timeout: 3000 });
    console.log('✓ 右箭头键已发送');

    await sleep(2000);

    console.log('发送左箭头键...');
    const psScript2 = `
      Add-Type -AssemblyName System.Windows.Forms
      [System.Windows.Forms.SendKeys]::SendWait("{LEFT}")
    `;

    await execAsync(`powershell -Command "${psScript2}"`, { timeout: 3000 });
    console.log('✓ 左箭头键已发送');

    console.log('\n✅ 按键测试完成！');
    console.log('如果PowerPoint没有翻页，可能的原因：');
    console.log('1. PowerPoint不在前台');
    console.log('2. PowerPoint不在演示模式');
    console.log('3. 没有打开演示文稿');

  } catch (error) {
    console.error('❌ 按键发送失败:', error.message);
  }

  console.log('\n========================================');
}

function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}

testSimpleKeys().catch(error => {
  console.error('测试过程中发生错误:', error);
  process.exit(1);
});